<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      /* 
      因为是四个数组中的任意值，所以四数之和可以改成两数之和的做法
      
      */
      var fourSumCount = function (nums1, nums2, nums3, nums4) {
        let map = new Map();
        for (let i = 0; i < nums1.length; i++) {
          for (let j = 0; j < nums2.length; j++) {
            let res = nums1[i] + nums2[j];
            if (map.has(res)) {
              map.set(res, map.get(res) + 1);
            } else {
              map.set(res, 1);
            }
          }
        }
        let result = 0;
        for (let i = 0; i < nums3.length; i++) {
          for (let j = 0; j < nums4.length; j++) {
            let v = 0 - (nums3[i] + nums4[j]);
            if (map.has(v)) {
              result += map.get(v);
            }
          }
        }
        return result;
      };
    </script>
  </body>
</html>
